package com.weixing.mall.provider.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoNeedAccess;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.vo.report.advertisement.*;
import com.weixing.mall.provider.service.IDayReportAdvertisementService;
import com.weixing.mall.provider.util.EasyExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @author jzy
 * @date 2020/6/6
 */
@RestController
@RequestMapping("report")
@Api(value = "后台报表APi", tags = "后台报表-广告部报表")
public class ReportAdvertisementController extends BaseController {

    @Autowired
    private IDayReportAdvertisementService advertisementService;


    @ApiOperation(value = "广告部报表--1广告")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "chatNum", value = "平台号",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间（投放）",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间（投放）",required = false, paramType = "query"),
    })
    @GetMapping("/advertisement/page")
    public Result<IPage<AdvertisementDetailVo>> advertisementPage(String chatNum,String startTime,String endTime){
        IPage<AdvertisementDetailVo> page = advertisementService.advertisementPage(chatNum, startTime, endTime, initMpPage());
        return ResultUtil.success(page);
    }
    @ApiOperation(value = "广告部报表--1广告-导出excel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "chatNum", value = "平台号",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间（投放）",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间（投放）",required = false, paramType = "query"),
    })
    @GetMapping("/advertisement/page/excel")
    @NoNeedAccess
    public void advertisementPageExcel(String chatNum, String startTime, String endTime, HttpServletResponse response){
        IPage<AdvertisementDetailVo> page = advertisementService.advertisementPage(chatNum, startTime, endTime, new Page(1,-1));
        try {
            EasyExcelUtil.writeExcel(response,AdvertisementDetailVo.class,page.getRecords(),"广告报表");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "广告部报表--3广告服务数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "agentName", value = "姓名",required = false, paramType = "query"),
            @ApiImplicitParam(name = "directorId", value = "广告员ID",required = false, paramType = "query"),
            @ApiImplicitParam(name = "wechatNum", value = "微信号",required = false, paramType = "query"),
            @ApiImplicitParam(name = "chatNum", value = "平台号",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间（投放）",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间（投放）",required = false, paramType = "query"),
    })
    @GetMapping("/advertisement/service/data")
    public Result<IPage<AdvertisementServiceDataVo>> advertisementServiceData(String agentName,Long directorId,String wechatNum,String chatNum,String startTime,String endTime){
        IPage<AdvertisementServiceDataVo> page = advertisementService.advertisementServiceData(agentName,directorId,wechatNum, chatNum, startTime, endTime, initMpPage());
        return ResultUtil.success(page);
    }
    @ApiOperation(value = "广告部报表--3广告服务数据-导出excel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "agentName", value = "姓名",required = false, paramType = "query"),
            @ApiImplicitParam(name = "directorId", value = "广告员ID",required = false, paramType = "query"),
            @ApiImplicitParam(name = "wechatNum", value = "微信号",required = false, paramType = "query"),
            @ApiImplicitParam(name = "chatNum", value = "平台号",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间（投放）",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间（投放）",required = false, paramType = "query"),
    })
    @GetMapping("/advertisement/service/data/excel")
    @NoNeedAccess
    public void advertisementServiceDataExcel(String agentName,Long directorId,String wechatNum,String chatNum,String startTime,String endTime,HttpServletResponse response) {
        IPage<AdvertisementServiceDataVo> page = advertisementService.advertisementServiceData(agentName,directorId,wechatNum, chatNum, startTime, endTime, new Page(1,-1));
        try {
            EasyExcelUtil.writeExcel(response,AdvertisementServiceDataVo.class,page.getRecords(),"广告服务数据");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @ApiOperation(value = "广告部报表--4广告投放报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "directorName", value = "广告专员名称",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间（投放）",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间（投放）",required = false, paramType = "query"),
    })
    @GetMapping("/advertisement/launch")
    public Result<IPage<AdvertisementLaunchReportVo>> advertisementLaunchReport(String directorName,String startTime,String endTime){
        IPage<AdvertisementLaunchReportVo> page = advertisementService.advertisementLaunchReport(directorName, startTime, endTime, initMpPage());
        return ResultUtil.success(page);
    }
    @ApiOperation(value = "广告部报表--4广告投放报表-导出excel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "directorName", value = "广告专员名称",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间（投放）",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间（投放）",required = false, paramType = "query"),
    })
    @GetMapping("/advertisement/launch/excel")
    @NoNeedAccess
    public void advertisementLaunchReportExcel(String directorName,String startTime,String endTime,HttpServletResponse response){
        IPage<AdvertisementLaunchReportVo> page = advertisementService.advertisementLaunchReport(directorName, startTime, endTime, new Page(1,-1));
        try {
            EasyExcelUtil.writeExcel(response,AdvertisementLaunchReportVo.class,page.getRecords(),"广告投放报表");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "广告部报表--5广告员性价比")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "directorName", value = "广告专员名称",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间（投放）",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间（投放）",required = false, paramType = "query"),
    })
    @GetMapping("/advertisement/director/performance")
    public Result<IPage<AdvertisementDirectorPerformanceVo>> advertisementDirectorPerformance(String directorName,String startTime,String endTime){
        IPage<AdvertisementDirectorPerformanceVo> page = advertisementService.advertisementDirectorPerformance(directorName, startTime, endTime, initMpPage());
        return ResultUtil.success(page);
    }
    @ApiOperation(value = "广告部报表--5广告员性价比-导出excel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "directorName", value = "广告专员名称",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间（投放）",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间（投放）",required = false, paramType = "query"),
    })
    @GetMapping("/advertisement/director/performance/excel")
    @NoNeedAccess

    public void advertisementDirectorPerformanceExcel(String directorName,String startTime,String endTime,HttpServletResponse response){
        IPage<AdvertisementDirectorPerformanceVo> page = advertisementService.advertisementDirectorPerformance(directorName, startTime, endTime, new Page(1,-1));
        try {
            EasyExcelUtil.writeExcel(response,AdvertisementDirectorPerformanceVo.class,page.getRecords(),"广告员性价比");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "广告部报表--6平台性价比")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yearMonth", value = "月份",required = false, paramType = "query"),
            @ApiImplicitParam(name = "platformName", value = "平台名称",required = false, paramType = "query"),
            @ApiImplicitParam(name = "platform", value = "平台",required = false, paramType = "query"),
            @ApiImplicitParam(name = "pageSite", value = "版面位置",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间（投放）",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间（投放）",required = false, paramType = "query")
    })
    @GetMapping("/advertisement/platform/performance")
    public Result<IPage<AdvertisementPlatformPerformanceVo>> advertisementPlatformPerformance(String yearMonth,String platformName,Long platform,Integer pageSite,String startTime,String endTime){
        IPage<AdvertisementPlatformPerformanceVo> page = advertisementService.advertisementPlatformPerformance(yearMonth,platformName,platform, pageSite, startTime, endTime, initMpPage());
        return ResultUtil.success(page);
    }
    @ApiOperation(value = "广告部报表--6平台性价比-导出excel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yearMonth", value = "月份",required = false, paramType = "query"),
            @ApiImplicitParam(name = "platformName", value = "平台名称",required = false, paramType = "query"),
            @ApiImplicitParam(name = "platform", value = "平台",required = false, paramType = "query"),
            @ApiImplicitParam(name = "pageSite", value = "版面位置",required = false, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间（投放）",required = false, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间（投放）",required = false, paramType = "query")
    })
    @GetMapping("/advertisement/platform/performance/excel")
    @NoNeedAccess
    public void advertisementPlatformPerformanceExcel(String yearMonth,String platformName,Long platform,Integer pageSite,String startTime,String endTime,HttpServletResponse response){
        IPage<AdvertisementPlatformPerformanceVo> page = advertisementService.advertisementPlatformPerformance(yearMonth,platformName,platform, pageSite, startTime, endTime, new Page(1,-1));
        try {
            EasyExcelUtil.writeExcel(response,AdvertisementPlatformPerformanceVo.class,page.getRecords(),"平台性价比");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @ApiOperation(value = "广告部报表--6平台性价比月报")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "platform", value = "平台",required = false, paramType = "query"),
            @ApiImplicitParam(name = "pageSite", value = "版面位置",required = false, paramType = "query"),
            @ApiImplicitParam(name = "yearMonth", value = "年月",required = false, paramType = "query")
    })
    @GetMapping("/advertisement/platform/performance/month")
    public Result<IPage<AdvertisementPlatformPerformanceVo>> advertisementPlatformPerformanceMonth(Long platform,Integer pageSite,String yearMonth){
        IPage<AdvertisementPlatformPerformanceVo> page = advertisementService.advertisementPlatformPerformanceMonth(platform, pageSite, yearMonth, initMpPage());
        return ResultUtil.success(page);
    }
    @ApiOperation(value = "广告部报表--6平台性价比月报-导出excel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "platform", value = "平台",required = false, paramType = "query"),
            @ApiImplicitParam(name = "pageSite", value = "版面位置",required = false, paramType = "query"),
            @ApiImplicitParam(name = "yearMonth", value = "年月",required = false, paramType = "query")
    })
    @GetMapping("/advertisement/platform/performance/month/excel")
    @NoNeedAccess
    public void advertisementPlatformPerformanceMonthExcel(Long platform,Integer pageSite,String yearMonth,HttpServletResponse response){
        IPage<AdvertisementPlatformPerformanceVo> page = advertisementService.advertisementPlatformPerformanceMonth(platform, pageSite, yearMonth, new Page(1,-1));
        try {
            EasyExcelUtil.writeExcel(response,AdvertisementPlatformPerformanceVo.class,page.getRecords(),"平台性价比月报");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
